using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;

namespace csctp
{
	public class ctp_quote
	{
        private readonly List<Delegate> _listDele = new List<Delegate>();
        Delegate AddDele(Delegate d) { _listDele.Add(d); return d; }

		#region	响应函数 extern
		public delegate void DeleFrontConnected();
		/// <summary>
		/// 当客户端与交易后台建立起通信连接时（还未登录前），该方法被调用。
		/// </summary>
		public DeleFrontConnected OnFrontConnected = null;
		private void onFrontConnected()
        {
			if (OnFrontConnected == null)
            {
				return;
            }
			OnFrontConnected();
		}
		public delegate void DeleFrontDisconnected(int nReason);
		/// <summary>
		/// 当客户端与交易后台通信连接断开时，该方法被调用。当发生这个情况后，API会自动重新连接，客户端可不做处理。
		/// </summary>
		public DeleFrontDisconnected OnFrontDisconnected = null;
		private void onFrontDisconnected(int nReason)
        {
			if (OnFrontDisconnected == null)
            {
				return;
            }
			OnFrontDisconnected(nReason);
		}
		public delegate void DeleHeartBeatWarning(int nTimeLapse);
		/// <summary>
		/// 心跳超时警告。当长时间未收到报文时，该方法被调用。
		/// </summary>
		public DeleHeartBeatWarning OnHeartBeatWarning = null;
		private void onHeartBeatWarning(int nTimeLapse)
        {
			if (OnHeartBeatWarning == null)
            {
				return;
            }
			OnHeartBeatWarning(nTimeLapse);
		}
		public delegate void DeleRspUserLogin(CThostFtdcRspUserLoginField pRspUserLogin, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 登录请求响应
		/// </summary>
		public DeleRspUserLogin OnRspUserLogin = null;
		private void onRspUserLogin(IntPtr  pRspUserLogin, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspUserLogin == null)
            {
				return;
            }			
			var ppRspUserLogin = new CThostFtdcRspUserLoginField();
			if (pRspUserLogin != IntPtr.Zero)
			{
				ppRspUserLogin = Marshal.PtrToStructure<CThostFtdcRspUserLoginField>(pRspUserLogin);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspUserLogin(ppRspUserLogin, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspUserLogout(CThostFtdcUserLogoutField pUserLogout, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 登出请求响应
		/// </summary>
		public DeleRspUserLogout OnRspUserLogout = null;
		private void onRspUserLogout(IntPtr  pUserLogout, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspUserLogout == null)
            {
				return;
            }			
			var ppUserLogout = new CThostFtdcUserLogoutField();
			if (pUserLogout != IntPtr.Zero)
			{
				ppUserLogout = Marshal.PtrToStructure<CThostFtdcUserLogoutField>(pUserLogout);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspUserLogout(ppUserLogout, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspQryMulticastInstrument(CThostFtdcMulticastInstrumentField pMulticastInstrument, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 请求查询组播合约响应
		/// </summary>
		public DeleRspQryMulticastInstrument OnRspQryMulticastInstrument = null;
		private void onRspQryMulticastInstrument(IntPtr  pMulticastInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspQryMulticastInstrument == null)
            {
				return;
            }			
			var ppMulticastInstrument = new CThostFtdcMulticastInstrumentField();
			if (pMulticastInstrument != IntPtr.Zero)
			{
				ppMulticastInstrument = Marshal.PtrToStructure<CThostFtdcMulticastInstrumentField>(pMulticastInstrument);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspQryMulticastInstrument(ppMulticastInstrument, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspError(CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 错误应答
		/// </summary>
		public DeleRspError OnRspError = null;
		private void onRspError(IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspError == null)
            {
				return;
            }			
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspError(ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspSubMarketData(CThostFtdcSpecificInstrumentField pSpecificInstrument, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 订阅行情应答
		/// </summary>
		public DeleRspSubMarketData OnRspSubMarketData = null;
		private void onRspSubMarketData(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspSubMarketData == null)
            {
				return;
            }			
			var ppSpecificInstrument = new CThostFtdcSpecificInstrumentField();
			if (pSpecificInstrument != IntPtr.Zero)
			{
				ppSpecificInstrument = Marshal.PtrToStructure<CThostFtdcSpecificInstrumentField>(pSpecificInstrument);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspSubMarketData(ppSpecificInstrument, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspUnSubMarketData(CThostFtdcSpecificInstrumentField pSpecificInstrument, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 取消订阅行情应答
		/// </summary>
		public DeleRspUnSubMarketData OnRspUnSubMarketData = null;
		private void onRspUnSubMarketData(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspUnSubMarketData == null)
            {
				return;
            }			
			var ppSpecificInstrument = new CThostFtdcSpecificInstrumentField();
			if (pSpecificInstrument != IntPtr.Zero)
			{
				ppSpecificInstrument = Marshal.PtrToStructure<CThostFtdcSpecificInstrumentField>(pSpecificInstrument);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspUnSubMarketData(ppSpecificInstrument, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspSubForQuoteRsp(CThostFtdcSpecificInstrumentField pSpecificInstrument, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 订阅询价应答
		/// </summary>
		public DeleRspSubForQuoteRsp OnRspSubForQuoteRsp = null;
		private void onRspSubForQuoteRsp(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspSubForQuoteRsp == null)
            {
				return;
            }			
			var ppSpecificInstrument = new CThostFtdcSpecificInstrumentField();
			if (pSpecificInstrument != IntPtr.Zero)
			{
				ppSpecificInstrument = Marshal.PtrToStructure<CThostFtdcSpecificInstrumentField>(pSpecificInstrument);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspSubForQuoteRsp(ppSpecificInstrument, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRspUnSubForQuoteRsp(CThostFtdcSpecificInstrumentField pSpecificInstrument, CThostFtdcRspInfoField pRspInfo, int nRequestID, bool bIsLast);
		/// <summary>
		/// 取消订阅询价应答
		/// </summary>
		public DeleRspUnSubForQuoteRsp OnRspUnSubForQuoteRsp = null;
		private void onRspUnSubForQuoteRsp(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast)
        {
			if (OnRspUnSubForQuoteRsp == null)
            {
				return;
            }			
			var ppSpecificInstrument = new CThostFtdcSpecificInstrumentField();
			if (pSpecificInstrument != IntPtr.Zero)
			{
				ppSpecificInstrument = Marshal.PtrToStructure<CThostFtdcSpecificInstrumentField>(pSpecificInstrument);
			}
						
			var ppRspInfo = new CThostFtdcRspInfoField();
			if (pRspInfo != IntPtr.Zero)
			{
				ppRspInfo = Marshal.PtrToStructure<CThostFtdcRspInfoField>(pRspInfo);
			}
			
			OnRspUnSubForQuoteRsp(ppSpecificInstrument, ppRspInfo, nRequestID, bIsLast);
		}
		public delegate void DeleRtnDepthMarketData(CThostFtdcDepthMarketDataField pDepthMarketData);
		/// <summary>
		/// 深度行情通知
		/// </summary>
		public DeleRtnDepthMarketData OnRtnDepthMarketData = null;
		private void onRtnDepthMarketData(IntPtr  pDepthMarketData)
        {
			if (OnRtnDepthMarketData == null)
            {
				return;
            }			
			var ppDepthMarketData = new CThostFtdcDepthMarketDataField();
			if (pDepthMarketData != IntPtr.Zero)
			{
				ppDepthMarketData = Marshal.PtrToStructure<CThostFtdcDepthMarketDataField>(pDepthMarketData);
			}
			
			OnRtnDepthMarketData(ppDepthMarketData);
		}
		public delegate void DeleRtnForQuoteRsp(CThostFtdcForQuoteRspField pForQuoteRsp);
		/// <summary>
		/// 询价通知
		/// </summary>
		public DeleRtnForQuoteRsp OnRtnForQuoteRsp = null;
		private void onRtnForQuoteRsp(IntPtr  pForQuoteRsp)
        {
			if (OnRtnForQuoteRsp == null)
            {
				return;
            }			
			var ppForQuoteRsp = new CThostFtdcForQuoteRspField();
			if (pForQuoteRsp != IntPtr.Zero)
			{
				ppForQuoteRsp = Marshal.PtrToStructure<CThostFtdcForQuoteRspField>(pForQuoteRsp);
			}
			
			OnRtnForQuoteRsp(ppForQuoteRsp);
		}
		
		#endregion

		IntPtr _handle = IntPtr.Zero, _api = IntPtr.Zero, _spi = IntPtr.Zero;
		
		public ctp_quote()
		{
			Directory.CreateDirectory("log");
			_api = qCreateApi();
			_spi = qCreateSpi();
			qRegisterSpi(_api, _spi);

			#region 注册事件,用adddele避免被回收
			qSetOnFrontConnected(_spi, (deleFrontConnected)AddDele(new deleFrontConnected((onFrontConnected))));
			qSetOnFrontDisconnected(_spi, (deleFrontDisconnected)AddDele(new deleFrontDisconnected((onFrontDisconnected))));
			qSetOnHeartBeatWarning(_spi, (deleHeartBeatWarning)AddDele(new deleHeartBeatWarning((onHeartBeatWarning))));
			qSetOnRspUserLogin(_spi, (deleRspUserLogin)AddDele(new deleRspUserLogin((onRspUserLogin))));
			qSetOnRspUserLogout(_spi, (deleRspUserLogout)AddDele(new deleRspUserLogout((onRspUserLogout))));
			qSetOnRspQryMulticastInstrument(_spi, (deleRspQryMulticastInstrument)AddDele(new deleRspQryMulticastInstrument((onRspQryMulticastInstrument))));
			qSetOnRspError(_spi, (deleRspError)AddDele(new deleRspError((onRspError))));
			qSetOnRspSubMarketData(_spi, (deleRspSubMarketData)AddDele(new deleRspSubMarketData((onRspSubMarketData))));
			qSetOnRspUnSubMarketData(_spi, (deleRspUnSubMarketData)AddDele(new deleRspUnSubMarketData((onRspUnSubMarketData))));
			qSetOnRspSubForQuoteRsp(_spi, (deleRspSubForQuoteRsp)AddDele(new deleRspSubForQuoteRsp((onRspSubForQuoteRsp))));
			qSetOnRspUnSubForQuoteRsp(_spi, (deleRspUnSubForQuoteRsp)AddDele(new deleRspUnSubForQuoteRsp((onRspUnSubForQuoteRsp))));
			qSetOnRtnDepthMarketData(_spi, (deleRtnDepthMarketData)AddDele(new deleRtnDepthMarketData((onRtnDepthMarketData))));
			qSetOnRtnForQuoteRsp(_spi, (deleRtnForQuoteRsp)AddDele(new deleRtnForQuoteRsp((onRtnForQuoteRsp))));
			
			#endregion
		}
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qCreateApi();
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qCreateSpi();
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qGetVersion();
		public string GetVersion() => Marshal.PtrToStringAnsi(qGetVersion())??"";
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qRelease(IntPtr api);
		/// <summary>
		/// 创建MdApi
		/// </summary>
		public void Release()
		{
			qRelease(_api);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qInit(IntPtr api);
		/// <summary>
		/// 初始化
		/// </summary>
		public void Init()
		{
			qInit(_api);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qJoin(IntPtr api);
		/// <summary>
		/// 等待接口线程结束运行
		/// </summary>
		public void Join()
		{
			qJoin(_api);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qRegisterFront(IntPtr api, string pszFrontAddress);
		/// <summary>
		/// 注册前置机网络地址
		/// </summary>
		public void RegisterFront(string pszFrontAddress)
		{
			qRegisterFront(_api, pszFrontAddress);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qRegisterNameServer(IntPtr api, string pszNsAddress);
		/// <summary>
		/// @remark RegisterNameServer优先于RegisterFront
		/// </summary>
		public void RegisterNameServer(string pszNsAddress)
		{
			qRegisterNameServer(_api, pszNsAddress);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qRegisterFensUserInfo(IntPtr api, ref CThostFtdcFensUserInfoField  pFensUserInfo);
		/// <summary>
		/// 注册名字服务器用户信息
		/// </summary>
		public void RegisterFensUserInfo(CThostFtdcFensUserInfoField  pFensUserInfo)
		{
			qRegisterFensUserInfo(_api, ref  pFensUserInfo);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qRegisterSpi(IntPtr api, IntPtr pSpi);
		/// <summary>
		/// 注册回调接口
		/// </summary>
		public void RegisterSpi(IntPtr pSpi)
		{
			qRegisterSpi(_api, pSpi);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSubscribeMarketData(IntPtr api, IntPtr ppInstrumentID, int nCount);
		/// <summary>
		/// 订阅行情。
		/// </summary>
		public void SubscribeMarketData(IntPtr ppInstrumentID, int nCount)
		{
			qSubscribeMarketData(_api, ppInstrumentID, nCount);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qUnSubscribeMarketData(IntPtr api, IntPtr ppInstrumentID, int nCount);
		/// <summary>
		/// 退订行情。
		/// </summary>
		public void UnSubscribeMarketData(IntPtr ppInstrumentID, int nCount)
		{
			qUnSubscribeMarketData(_api, ppInstrumentID, nCount);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSubscribeForQuoteRsp(IntPtr api, IntPtr ppInstrumentID, int nCount);
		/// <summary>
		/// 订阅询价。
		/// </summary>
		public void SubscribeForQuoteRsp(IntPtr ppInstrumentID, int nCount)
		{
			qSubscribeForQuoteRsp(_api, ppInstrumentID, nCount);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qUnSubscribeForQuoteRsp(IntPtr api, IntPtr ppInstrumentID, int nCount);
		/// <summary>
		/// 退订询价。
		/// </summary>
		public void UnSubscribeForQuoteRsp(IntPtr ppInstrumentID, int nCount)
		{
			qUnSubscribeForQuoteRsp(_api, ppInstrumentID, nCount);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qReqUserLogin(IntPtr api, ref CThostFtdcReqUserLoginField pReqUserLoginField, int nRequestID);
		/// <summary>
		/// 用户登录请求
		/// </summary>
		public void ReqUserLogin(CThostFtdcReqUserLoginField pReqUserLoginField, int nRequestID)
		{
			qReqUserLogin(_api, ref pReqUserLoginField, nRequestID);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qReqUserLogout(IntPtr api, ref CThostFtdcUserLogoutField pUserLogout, int nRequestID);
		/// <summary>
		/// 登出请求
		/// </summary>
		public void ReqUserLogout(CThostFtdcUserLogoutField pUserLogout, int nRequestID)
		{
			qReqUserLogout(_api, ref pUserLogout, nRequestID);
		}
		
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qReqQryMulticastInstrument(IntPtr api, ref CThostFtdcQryMulticastInstrumentField pQryMulticastInstrument, int nRequestID);
		/// <summary>
		/// 请求查询组播合约
		/// </summary>
		public void ReqQryMulticastInstrument(CThostFtdcQryMulticastInstrumentField pQryMulticastInstrument, int nRequestID)
		{
			qReqQryMulticastInstrument(_api, ref pQryMulticastInstrument, nRequestID);
		}
		

		#region 注册响应函数
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleFrontConnected();
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnFrontConnected(IntPtr spi, deleFrontConnected func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleFrontDisconnected(int nReason);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnFrontDisconnected(IntPtr spi, deleFrontDisconnected func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleHeartBeatWarning(int nTimeLapse);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnHeartBeatWarning(IntPtr spi, deleHeartBeatWarning func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspUserLogin(IntPtr  pRspUserLogin, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspUserLogin(IntPtr spi, deleRspUserLogin func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspUserLogout(IntPtr  pUserLogout, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspUserLogout(IntPtr spi, deleRspUserLogout func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspQryMulticastInstrument(IntPtr  pMulticastInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspQryMulticastInstrument(IntPtr spi, deleRspQryMulticastInstrument func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspError(IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspError(IntPtr spi, deleRspError func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspSubMarketData(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspSubMarketData(IntPtr spi, deleRspSubMarketData func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspUnSubMarketData(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspUnSubMarketData(IntPtr spi, deleRspUnSubMarketData func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspSubForQuoteRsp(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspSubForQuoteRsp(IntPtr spi, deleRspSubForQuoteRsp func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRspUnSubForQuoteRsp(IntPtr  pSpecificInstrument, IntPtr  pRspInfo, int nRequestID, bool bIsLast);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRspUnSubForQuoteRsp(IntPtr spi, deleRspUnSubForQuoteRsp func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRtnDepthMarketData(IntPtr  pDepthMarketData);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRtnDepthMarketData(IntPtr spi, deleRtnDepthMarketData func);
		
		[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)]
		private delegate void deleRtnForQuoteRsp(IntPtr  pForQuoteRsp);
		[DllImport("ctp_quote.dll", CallingConvention = CallingConvention.Cdecl)]
		private static extern IntPtr qSetOnRtnForQuoteRsp(IntPtr spi, deleRtnForQuoteRsp func);
		
		#endregion
	}
}